#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000001;
int step = 0;
void bfs(int sx , int ex){
	set<int>q1;
	set<int>q2;
	set<int>visted;
	set<int>tmp;
	q1.insert(sx);
	q2.insert(ex);
	while(q1.size() && q2.size()){
		tmp.clear();
		for(set<int>::iterator it = q1.begin();it != q1.end() ; it++){
			int cur = *it;
			if(q2.find(cur) != q2.end()){
				cout << step << endl;
				return;
			}
			visted.insert(cur);
			for(int i = 1 ; i <= 3 ; i++){
				int nc = cur;
				if(i == 1)nc++;
				if(i == 2)nc--;
				if(i == 3){
					if(step % 2 != 0){
						if(nc % 2 == 0){
							nc /= 2;
						}
						else continue;
					}
					else{
						nc *= 2;
					}
				}
				if(nc >= 0 && nc <= 100000 && visted.find(nc) == visted.end()){
					tmp.insert(nc);
				}
			}
		}
		step++;
		q1 = q2;
		q2 = tmp;
	}
}
int main(){
	int m;
	cin >> m;
	for(int i = 1 ; i <= m ; i++){
		int n , k;
		cin >> n >> k;
		bfs(n , k);
	}
	return 0;
}
